unit uEditItem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, IniFiles, ComCtrls;

type
  TfEditItem = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn4: TBitBtn;
    Bevel1: TBevel;
    Image1: TImage;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    Edit3: TEdit;
    Label7: TLabel;
    Label3: TLabel;
    SlotBox: TComboBox;
    Bevel2: TBevel;
    Image2: TImage;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    GroupBox2: TGroupBox;
    Edit10: TEdit;
    Label11: TLabel;
    Edit11: TEdit;
    Label12: TLabel;
    Edit12: TEdit;
    Label13: TLabel;
    Edit13: TEdit;
    Label14: TLabel;
    Label15: TLabel;
    Edit14: TEdit;
    Edit15: TEdit;
    Label16: TLabel;
    UpDown1: TUpDown;
    Edit16: TComboBox;
    Label17: TLabel;
    RG1: TRadioGroup;
    Label18: TLabel;
    Edit17: TEdit;
    Label19: TLabel;
    Edit18: TEdit;
    Label20: TLabel;
    Edit19: TEdit;
    UpDown2: TUpDown;
    procedure BitBtn4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ImageIndex, DollID: Integer;
  end;

var
  fEditItem: TfEditItem;

implementation

uses untSellect, untImage, untMain, uSellectDollImage, uBox;

{$R *.dfm}

procedure TfEditItem.BitBtn4Click(Sender: TObject);
begin
  frmMain.SGClick(Sender);
end;

procedure TfEditItem.FormShow(Sender: TObject);
var
  I: Integer;
begin
  Image1.Picture := frmImage.Image1.Picture;
  with frmMain do
  begin
    Edit1.Text  := ISG.Cells[1, ItemRow];
    Edit2.Text  := ISG.Cells[2, ItemRow];
    Edit3.Text  := ISG.Cells[3, ItemRow];
    if Trim(ISG.Cells[4, ItemRow]) = '' then I := 0 else I := StrToInt(ISG.Cells[4, ItemRow]);
    SlotBox.ItemIndex := I;
    if Trim(ISG.Cells[5, ItemRow]) = '' then I := 0 else I := StrToInt(ISG.Cells[5, ItemRow]);
    DollID := I;
    Edit4.Text  := ISG.Cells[ 6, ItemRow];
    Edit5.Text  := ISG.Cells[ 7, ItemRow];
    Edit6.Text  := ISG.Cells[ 8, ItemRow];
    Edit7.Text  := ISG.Cells[ 9, ItemRow];
    Edit17.Text := ISG.Cells[10, ItemRow];
    if Trim(ISG.Cells[11, ItemRow]) = '' then I := 0
      else I := StrToInt(ISG.Cells[11, ItemRow]);
    ImageIndex  := I;
    Edit8.Text  := ISG.Cells[12, ItemRow];
    Edit9.Text  := ISG.Cells[13, ItemRow];
    Edit10.Text := ISG.Cells[14, ItemRow];
    Edit11.Text := ISG.Cells[15, ItemRow];
    Edit12.Text := ISG.Cells[16, ItemRow];
    Edit13.Text := ISG.Cells[17, ItemRow];
    Edit14.Text := ISG.Cells[18, ItemRow];
    Edit18.Text := ISG.Cells[19, ItemRow];
    Edit15.Text := ISG.Cells[20, ItemRow];
    Edit16.Text := ISG.Cells[21, ItemRow];
    if Trim(ISG.Cells[22, ItemRow]) = '' then I := 0
      else I := StrToInt(ISG.Cells[22, ItemRow]);
    RG1.ItemIndex := I;
    Edit19.Text := ISG.Cells[23, ItemRow];
  end;
end;

procedure TfEditItem.Image1Click(Sender: TObject);
begin
  frmSellect.ShowModal;
end;

procedure TfEditItem.BitBtn1Click(Sender: TObject);
var
  E: TIniFile;
begin
  // OK
  with frmMain do
  begin
    ISG.Cells[ 0, ItemRow] := IntToStr(ItemRow + 1);
    ISG.Cells[ 1, ItemRow] := Edit1.Text;
    ISG.Cells[ 2, ItemRow] := Edit2.Text;
    ISG.Cells[ 3, ItemRow] := Edit3.Text;
    ISG.Cells[ 4, ItemRow] := IntToStr(SlotBox.ItemIndex);
    ISG.Cells[ 5, ItemRow] := IntToStr(DollID);
    ISG.Cells[ 6, ItemRow] := Edit4.Text;
    ISG.Cells[ 7, ItemRow] := Edit5.Text;
    ISG.Cells[ 8, ItemRow] := Edit6.Text;
    ISG.Cells[ 9, ItemRow] := Edit7.Text;
    ISG.Cells[10, ItemRow] := Edit17.Text;
    ISG.Cells[11, ItemRow] := IntToStr(ImageIndex);
    ISG.Cells[12, ItemRow] := Edit8.Text;
    ISG.Cells[13, ItemRow] := Edit9.Text;
    ISG.Cells[14, ItemRow] := Edit10.Text;
    ISG.Cells[15, ItemRow] := Edit11.Text;
    ISG.Cells[16, ItemRow] := Edit12.Text;
    ISG.Cells[17, ItemRow] := Edit13.Text;
    ISG.Cells[18, ItemRow] := Edit14.Text;
    ISG.Cells[19, ItemRow] := Edit18.Text;
    ISG.Cells[20, ItemRow] := Edit15.Text;
    ISG.Cells[21, ItemRow] := Edit16.Text;
    ISG.Cells[22, ItemRow] := IntToStr(RG1.ItemIndex);
    ISG.Cells[23, ItemRow] := Edit19.Text;

    {
    if CB1.Checked then S1 := '1' else S1 := '0';
    }
    //
    E := TINIFile.Create('data\items.ini');
    E.WriteString(IntToStr(ItemRow + 1), 'ImageIndex', IntToStr(ImageIndex));
    E.WriteString(IntToStr(ItemRow + 1), 'Name', Edit1.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Description', Edit2.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Dungeons', Edit3.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Type', IntToStr(SlotBox.ItemIndex));
    E.WriteString(IntToStr(ItemRow + 1), 'DollID', IntToStr(DollID));
    E.WriteString(IntToStr(ItemRow + 1), 'Strength', Edit4.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Dexterity', Edit5.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Stamina', Edit6.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Magic', Edit7.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Spirit', Edit17.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Damage', Edit8.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Protect', Edit9.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedLevel', Edit10.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedStrength', Edit11.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedDexterity', Edit12.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedStamina', Edit13.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedMagic', Edit14.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'NeedSpirit', Edit18.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Tough', Edit15.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Bonus', Edit16.Text);
    E.WriteString(IntToStr(ItemRow + 1), 'Gender', IntToStr(RG1.ItemIndex));
    E.WriteString(IntToStr(ItemRow + 1), 'Cost', Edit19.Text);
    //
    SG.RowCount := SG.RowCount + 1;
    E.Free;
  end;
end;

procedure TfEditItem.Image2Click(Sender: TObject);
begin
  fSellectDollImage.ShowModal;
end;

end.
